package com.tencreat.account.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.domain.account.MallSystem;
import com.tencreat.service.account.IMallSystemService;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统配置Controller
 *
 * @author tencreat
 * @date 2021-09-13
 */
@Api(tags="系统配置api")
@RestController
@RequestMapping("/system/system")
public class MallSystemController extends BaseController {
    @Autowired
    private IMallSystemService mallSystemService;

    /**
     * 查询系统配置列表
     */
    @ApiOperation(value="查询系统配置列表")
    @PreAuthorize("@ss.hasPermi('system:system:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallSystem>> list(@RequestBody  MallSystem mallSystem) {
        QueryWrapper<MallSystem> wrapper = Wrappers.query(mallSystem);
        Page<MallSystem> page =  new Page<>(mallSystem.getPageNum(), mallSystem.getPageSize());
        return HttpResult.ok(mallSystemService.page(page, wrapper));
    }

    /**
     * 导出系统配置列表
     */
    @ApiOperation(value="导出系统配置列表")
    @PreAuthorize("@ss.hasPermi('system:system:export')")
    @Log(title = "系统配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallSystem mallSystem) {
        List<MallSystem> list = mallSystemService.selectMallSystemList(mallSystem);
        ExcelUtil<MallSystem> util = new ExcelUtil<MallSystem>(MallSystem.class);
        return util.exportExcel(list, "system");
    }

    /**
     * 获取系统配置详细信息
     */
    @ApiOperation(value="获取系统配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:system:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallSystem> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallSystemService.selectMallSystemById(id));
    }

    /**
     * 获取系统配置详细信息
     */
    @ApiOperation(value="获取系统配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:system:query')")
    @PostMapping(value = "/getInfoByName")
    public HttpResult<MallSystem> getInfoByName(@RequestParam String name) {
        return HttpResult.ok(mallSystemService.selectMallSystemByName(name));
    }

    /**
     * 新增系统配置
     */
    @ApiOperation(value="新增系统配置")
    @PreAuthorize("@ss.hasPermi('system:system:add')")
    @Log(title = "系统配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallSystem mallSystem) {
        return to(mallSystemService.insertMallSystem(mallSystem));
    }

    /**
     * 修改系统配置
     */
    @ApiOperation(value="修改系统配置")
    @PreAuthorize("@ss.hasPermi('system:system:edit')")
    @Log(title = "消息中心>欢迎注册", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallSystem mallSystem) {
        return to(mallSystemService.updateMallSystem(mallSystem));
    }

    /**
     * 删除系统配置
     */
    @ApiOperation(value="删除系统配置")
    @PreAuthorize("@ss.hasPermi('system:system:remove')")
    @Log(title = "系统配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallSystemService.deleteMallSystemByIds(ids));
    }

    /**
     * 修改系统配置
     */
    @ApiOperation(value = "修改系统配置")
    @PreAuthorize("@ss.hasPermi('system:system:edit')")
    @Log(title = "系统配置", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/editKeyValueByName")
    public HttpResult<Boolean> editKeyValueByName(@RequestBody MallSystem mallSystem) {
        return to(mallSystemService.editKeyValueByName(mallSystem));
    }
}
